﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.effects {
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import Classes.*;
    import com.zynga.skelly.util.color.*;

    public class ColorMatrixEffect extends MapResourceEffect {

        protected var m_isAnimationComplete:Boolean = false;
        protected var m_originalBitmapData:BitmapData;
        protected var m_effectBitmapData:BitmapData;
        protected var m_value:Number;

        public function ColorMatrixEffect(_arg1:MapResource, _arg2:Number){
            super(_arg1);
            this.m_value = _arg2;
            this.animate(1);
        }
        override public function animate(_arg1:uint):Boolean{
            if (this.m_isAnimationComplete){
                return (false);
            };
            if (isMapResourceLoaded){
                if (this.isDrawable){
                    this.drawEffect();
                };
                return (false);
            };
            return (true);
        }
        override public function reattach():void{
            if (this.isDrawable){
                this.drawEffect();
            };
        }
        override public function cleanUp():void{
            var _local1:Bitmap = this.getContentBitmap();
            if (((_local1) && (this.m_originalBitmapData))){
                _local1.bitmapData = this.m_originalBitmapData;
            };
            m_mapResource = null;
            this.m_originalBitmapData = null;
            this.m_isAnimationComplete = true;
        }
        protected function get isDrawable():Boolean{
            var _local1:Boolean;
            var _local2:Bitmap = this.getContentBitmap();
            if (!_local2){
                _local1 = false;
            } else {
                if (((this.m_effectBitmapData) && ((this.m_effectBitmapData == _local2.bitmapData)))){
                    _local1 = false;
                };
            };
            return (_local1);
        }
        protected function drawEffect():void{
            var _local2:Point;
            var _local1:Bitmap = this.getContentBitmap();
            this.m_originalBitmapData = _local1.bitmapData;
            if (this.bitmapDictionary[this.m_originalBitmapData]){
                this.m_effectBitmapData = this.bitmapDictionary[this.m_originalBitmapData];
            } else {
                this.m_effectBitmapData = this.m_originalBitmapData.clone();
                _local2 = new Point();
                this.m_effectBitmapData.applyFilter(this.m_effectBitmapData, this.m_effectBitmapData.rect, _local2, this.colorMatrix.filter);
                this.bitmapDictionary[this.m_originalBitmapData] = this.m_effectBitmapData;
            };
            _local1.bitmapData = this.m_effectBitmapData;
        }
        protected function get colorMatrix():ColorMatrix{
            return (null);
        }
        protected function get bitmapDictionary():Dictionary{
            return (null);
        }
        protected function getContentBitmap():Bitmap{
            var _local2:Bitmap;
            if (!m_mapResource){
                return (null);
            };
            var _local1:DisplayObject = m_mapResource.content;
            if ((_local1 is Bitmap)){
                _local2 = (_local1 as Bitmap);
            } else {
                if ((_local1 is CompositeItemImage)){
                    _local2 = ((_local1 as CompositeItemImage).getBuildingImageByType(ItemImageInstance.BUILDING_IMAGE) as Bitmap);
                };
            };
            return (_local2);
        }

    }
}//package Classes.effects 
